package my.fuelwallet.test;

import java.util.ArrayList;
import java.util.List;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.Window;
import android.widget.ListView;

public class SettingActivity extends ListActivity {
	private Handler updateHandler=new Handler(){
		public void handleMessage(Message msg){
			setProgressBarIndeterminateVisibility(false);
			
		}
		
	};
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
		setContentView(R.layout.setting);
		List<String> setting_option = new ArrayList<String>();
		setting_option.add("Account Manager");
		setting_option.add("Update prices");
		setting_option.add("Price list");
		setting_option.add("History");

		/*
		 * ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
		 * android.R.layout.simple_list_item_1, setting_option);
		 * setListAdapter(adapter);
		 * 
		 * List<IconItem> setting_option = new ArrayList<IconItem>();
		 * setting_option.add(new IconItem("New account","at.png"));
		 * setting_option.add(new IconItem("Update prices","au.png"));
		 * setting_option.add(new IconItem("Price list","be.png"));
		 * setting_option.add(new IconItem("History","br.png"));
		 */

		IconListAdapter adapter = new IconListAdapter(this,
				R.layout.icon_listitem, setting_option);

		setListAdapter(adapter);

	}

	protected void onListItemClick(ListView l, View v, int position, long id) {

		String option = l.getItemAtPosition(position).toString();
		if (option.equals("Account Manager")) {
			Intent intent = new Intent(SettingActivity.this,
					CarProfileManagerActivity.class);
			startActivity(intent);
		} else if (option.equals("Update prices")) {
			PriceUtility priceutility = new PriceUtility(this,updateHandler);
			setProgressBarIndeterminateVisibility(true);
			priceutility.startExecution();
			priceutility.analyze();
			priceutility.updateDatabase();
		} else if (option.equals("Price list")) {
			Intent intent3 = new Intent(SettingActivity.this, ShowPrice.class);
			startActivity(intent3);
		}

		super.onListItemClick(l, v, position, id);
	}

}